package com.hujun.utils.date;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class LocalDateUtils {

    public static final String YEAR_MONTH_DAY_HOUR_MINUTE_SECOND = "yyyy-MM-dd HH:mm:ss";

    public static final String YEAR_MONTH_DAY = "yyyy-MM-dd";


    /**
     * 将字符串yyyy-MM-dd格式的日期转为LocalDate
     * @param str 格式yyyy-MM-dd
     * @return
     */
    public static LocalDate convertToLocalDate(String str) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(YEAR_MONTH_DAY);
        return LocalDate.parse(str, formatter);
    }

    public static LocalDate convertToLocalDate(String str, DateTimeFormatter formatter) {
        return LocalDate.parse(str, formatter);
    }

    public static LocalDateTime convertToLocalDateTime(String str) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(YEAR_MONTH_DAY_HOUR_MINUTE_SECOND);
        return LocalDateTime.parse(str, formatter);
    }
}
